{template 'common/header'}
{template 'common'}

<ul class="nav nav-tabs">
	<li {if $operation == 'post' && empty($id)}class="active"{/if}><a href="{php echo $this->createWebUrl('foods', array('op' => 'post'))}">添加菜品</a></li>
	<li {if $operation == 'display'}class="active"{/if}><a href="{php echo $this->createWebUrl('foods', array('op' => 'display'))}">管理菜品</a></li>
    {if $operation == 'post' && !empty($id)}<li class="active"><a href="#">
    编辑菜品
    </a></li>{/if}
</ul>

{if $operation == 'post'}

<div class="main">

    <form action="" method="post" class="form-horizontal form" enctype="multipart/form-data" id="form1">
<input type="hidden" name="id" value="{$item['id']}" />
        <div class="panel panel-default">

            <div class="panel-heading">
                菜品信息
            </div>

            <div class="panel-body">

  <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">店铺与菜系</label>
                    <div class="col-sm-4">
<select name="pcate" onchange="fetchChildCategory(this.options[this.selectedIndex].value)" class='form-control'>
							<option value="0">请选择店铺</option>
						{loop $category $row}
						{if $row['parentid'] == 0}
						<option value="{$row['id']}" {if $row['id'] == $item['pcate']} selected="selected"{/if}>{$row['name']}</option>
						{/if}
						{/loop}
					</select>
                    </div>
                    <div class="col-sm-4">
                    <select id="cate_2" name="ccate" autocomplete="off" class='form-control'>
							<option value="0">请选择菜系</option>
						{if !empty($item['pcate']) && !empty($children[$item['pcate']])}
						{loop $children[$item['pcate']] $row}
						<option value="{$row[0]}" {if $row[0] == $item['ccate']} selected="selected"{/if}>{$row[1]}</option>
						{/loop}
						{/if}
					</select>
                    </div>   </div>
                    <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">菜品名称</label>
                    <div class="col-sm-9">
                        <input type="text" name="title" class="form-control" value="{$item['title']}" />
                    </div></div>
                     <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">菜品单位</label>
                    <div class="col-sm-9">
                        <input type="text" name="unit" class="form-control" value="{$item['unit']}" />
                    </div></div>
                     <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否上架</label>
                    <div class="col-sm-9">
                    <label class='radio-inline'>
                             <input type='radio' name='status' value='1' {if $item['status'] == 1 || empty($item['id'])}checked{/if} /> 是
                         </label>
                         <label class='radio-inline'>
                             <input type='radio' name='status' value='0' {if $item['status'] == 0 && !empty($item['id'])}checked{/if} /> 否
                         </label>
                    </div></div>
                     <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">是否推荐</label>
                    <div class="col-sm-9">
                    <label class='radio-inline'>
                             <input type='radio' name='ishot' value='1' {if $item['ishot'] == 1}checked{/if} /> 是
                         </label>
                         <label class='radio-inline'>
                             <input type='radio' name='ishot' value='0' {if $item['ishot'] == 0}checked{/if} /> 否
                         </label>
                    </div></div>
                 <div class="form-group">

                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">缩略图</label>

                    <div class="col-sm-9">

                        {php echo tpl_form_field_image('thumb', $item['thumb'])}

                    </div>

                </div>
            
                    <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">优惠价</label>
                    <div class="col-sm-9">
                    <div class="input-group">
                       <input type="text" class="form-control" name="preprice" value="{$item['preprice']}" />
                       <span class="input-group-addon">元</span>
                       </div>
                    </div></div>
                    <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">原价</label>
                    <div class="col-sm-9">
                    <div class="input-group">
                       <input type="text" class="form-control" name="oriprice" value="{$item['oriprice']}" />
                       <span class="input-group-addon">元</span>
                       </div>
                    </div></div>
                    <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">热度</label>
                    <div class="col-sm-9">
                    <div class="input-group">
                       <input type="text" class="form-control" name="hits" value="{$item['hits']}" />
                       <span class="input-group-addon">次</span>
                       </div>
                       <span class="help-block">已被顾客选择次数</span>
                    </div></div>

            </div>

        </div>
		<div class="form-group col-sm-12">

			<input type="submit" name="submit" value="提交" class="btn btn-primary col-lg-1" />

			<input type="hidden" name="token" value="{$_W['token']}" />

		</div>

    </form>

</div>
{elseif $operation == 'display'}

<div class="main">
 <div class="panel panel-info">

	<div class="panel-heading">筛选</div>

	<div class="panel-body">

		<form action="./index.php" method="get" class="form-horizontal" role="form">

			<input type="hidden" name="c" value="site" />

			<input type="hidden" name="a" value="entry" />

        	<input type="hidden" name="m" value="jufeng_wcy" />

        	<input type="hidden" name="do" value="foods" />

			<div class="form-group">

				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">关键字</label>

				<div class="col-sm-8 col-lg-9">

					<input class="form-control" name="keyword" id="" type="text" value="{$_GPC['keyword']}">

				</div>

			</div>

			<div class="form-group">

				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">状态</label>

				<div class="col-sm-8 col-lg-9">

					<select name="status" class='form-control'>
                            <option value="1" selected>上架</option>
							<option value="0">下架</option>
					</select>

				</div>

			</div>

            <div class="form-group">

				<label class="col-xs-12 col-sm-2 col-md-2 col-lg-1 control-label">分类</label>

				<div class="col-sm-4">
<select name="cate_1" onchange="fetchChildCategory(this.options[this.selectedIndex].value)" class='form-control'>
							<option value="0">请选择店铺</option>
						{loop $category $row}
						{if $row['parentid'] == 0}
						<option value="{$row['id']}" {if $row['id'] == $_GPC['cate_1']} selected="selected"{/if}>{$row['name']}</option>
						{/if}
						{/loop}
					</select>

				</div>

				<div class="col-sm-4">
 <select id="cate_2" name="cate_2" class='form-control input-medium'>
							<option value="0">请选择菜系</option>
						{if !empty($_GPC['cate_1']) && !empty($children[$_GPC['cate_1']])}
						{loop $children[$_GPC['cate_1']] $row}
						<option value="{$row[0]}" {if $row[0] == $_GPC['cate_2']} selected="selected"{/if}>{$row[1]}</option>
						{/loop}
						{/if}
					</select>

                </div>

				<div class=" col-xs-12 col-sm-2 col-lg-2">

					<button class="btn btn-default"><i class="fa fa-search"></i> 搜索菜品</button>

				</div>

			</div>

			<div class="form-group">

			</div>

		</form>

	</div>

</div>

<style>

.label{cursor:pointer;}

</style>

    <div class="category">

        <form action="" method="post" onsubmit="return formcheck(this)">

			<div class="panel panel-default">

				<div class="panel-body table-responsive">

					<table class="table table-hover">

						<thead>

							<tr>
					<th style="width:70px;">菜品ID</th>
					<th style="min-width:120px;">菜品标题</th>
					<th style="width:100px;">是否推荐</th>
					<th style="width:100px;">优惠价/原价</th>
					<th style="width:100px;">单位</th>
					<th style="width:100px;">状态</th>
					<th style="width:100px;">热度</th>
					<th style="text-align:right; min-width:60px;">操作</th>
				</tr>

						</thead>

					<tbody>
				{loop $list $item}
				<tr>
					<td>{$item['id']}</td>
					<td>{if !empty($category[$item['pcate']])}<span class="text-error">[{$category[$item['pcate']]['name']}] </span>{/if}{if !empty($children[$item['pcate']])}<span class="text-info">[{$children[$item['pcate']][$item['ccate']][1]}] </span>{/if}{$item['title']}</td>
					<td>{if $item['ishot']}<span class="label label-success">是</span>{else}<span class="label label-danger">否</span>{/if}</td>
					<td style="background:#f2dede;">{$item['preprice']}元 / {$item['oriprice']}元</td>
					<td>{$item['unit']}</td>
					<td>{if $item['status']}<span class="label label-success">上架</span>{else}<span class="label label-danger">下架</span>{/if}</td>
					<td>{$item['hits']}</td>
					<td style="text-align:right;">
						<a href="{php echo $this->createWebUrl('foods', array('id' => $item['id'], 'op' => 'post'))}">编辑</a>&nbsp;&nbsp;<a href="{php echo $this->createWebUrl('foods', array('id' => $item['id'], 'op' => 'delete'))}" onclick="return confirm('此操作不可恢复，确认删除？');return false;">删除</a>
					</td>
				</tr>
				{/loop}
			</tbody>

					</table>
{$pager}
				</div>

           </div>

        </form>

    </div>

</div>
{/if}
<script type="text/javascript">
<!--
	var category = {php echo json_encode($children)};
//-->
</script>


{template 'footer'}

